<?php
/**
 * Manages all items in this world.
 *
 * @author Mark Dohmen.
 */
final class ItemManager {
	
	/**
	 * Holds a list with items.
	 */
	private $items;
	
	/**
 	 * Loads all items in the system.
 	 */
	final public function load() {
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `item_definitions`");
		foreach ($data as $definition) {
			if (ItemDefintion::forId($definition['id']) === NULL) {
				ItemDefintion::addDefinition(
					new ItemDefintion(
						$definition['id'], 
						$definition['name'], 
						$definition['description'], 
						$definition['stackable'], 
						$definition['bonusses']
					)
				);
			}
		}
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `items`");
		foreach ($data as $item) {
			$this->items[] = new Item(
				NPCDefintion::forId($item['id']), 
				$item['count']
			);
		}
	}
	
	/**
	 * Gets the list with items.
	 *
	 * @return $items
	 */
	final public function getItems() {
		return (array) $this->items;	
	}
}
?>